<?php
include('../includes/config.php');

if($_POST['password'])
{
$id = $_GET['id'];
$reponse = mysql_query('SELECT * FROM liens_skyblog WHERE id = "'.$id.'"') or die(mysql_error());
$donnees = mysql_fetch_array($reponse);

	if(md5($_POST['password']) == $donnees['password'])
	{
	header('Location: '.html_entity_decode($donnees['lien']).'');
	//echo 'Vous serez redirigé vers '.$donnees['lien'].'...';
	}
	else {
	$passworderror = 1;
	$askpassword = 1;
	}
}

elseif($_GET['id'])
{
$id = $_GET['id'];
$reponse = mysql_query('SELECT * FROM liens_skyblog WHERE id = "'.$id.'"') or die(mysql_error());
$donnees = mysql_fetch_array($reponse);

	if($donnees['password'] == 'd41d8cd98f00b204e9800998ecf8427e')
	{
	header('Location: '.html_entity_decode($donnees['lien']).'');
	//echo 'Vous serez redirigé vers '.$donnees['lien'].'...';
	}
	else
	{
	$askpassword = 1;
	}
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="robots" content="index,follow" />
<link href="<?php echo $baseurl; ?>default.css" rel="stylesheet" title="Feuille de style principale" type="text/css" media="screen" />
<title>Protection de liens - Anothertime</title>
</head>
<body>

<div id="conteneur">

<div id="header">

<div id="col1">

<h1><a href="<?php echo $baseurl; ?>"><?php echo $nameblog; ?></a></h1>
<p class="baseline"><?php echo $baseline; ?></p>
</div>

<?php
include('../includes/pub.php');
?>

</div>

<div id="menu">
<?php
include('../includes/menu.php');
?>
</div>
<div id="blog">

<?php

if($askpassword)
{
?>
<h2>Quel est le mot de passe ?</h2>
<?php
if($passworderror)
echo '<p><strong>Le mot de passe n\'est pas bon, réessayer</strong></p>';
?>

<form  action="" method="post">
<p>
<label>Mot de passe :</label>
<input type="password" name="password" size="20" value="" />
<input type="hidden" name="idlien" value="<?php echo $_GET['id']; ?>" />

<p>
<p>
<input type="submit" value="Emmène-moi où je veux aller" />
</p>
</form>
<p>Toi aussi, <a href="index.php">sécurise ou masque un lien</a>.</p>

<?php
}

elseif($_POST['lien'])
{
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
$time = time();
$lien = mysql_real_escape_string(htmlentities($_POST['lien']));
$password = mysql_real_escape_string(md5($_POST['create_password']));
mysql_query("INSERT INTO liens_skyblog VALUES('', '$lien','$password', '$time', '$ip')");
$id=mysql_insert_id();
?>
<h2>Votre lien masqué ou sécurisé</h2>

<input type="text" size="50" value="<?php echo $baseurl; ?>liens/?id=<?php echo $id; ?>" />
<?php
}

else{
?>
<h2>Créer un lien</h2>

<form  action="" method="post">
<p>
<label>Votre lien :</label>
<input type="text" name="lien" size="50" value="http://" />
<br />
<label>Mot de passe :</label>
<input type="password" name="create_password" size="20" value="" />
<p>
<p>
<input type="submit" value="Masque et/ou protège mon lien" />
</p>
</form>
<?php
}
?>

<p>Service proposé par <a href="http://anothertime.skyrock.com">Anothertime</a>.</p>
</div>

<div id="sidebar-box">

<div id="sidebar">

<?php include("../includes/sidebar_content.php"); ?> </div>

</div>

</div>
</body>
</html>